﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Web;

    using MarketPulse.BusinessLogic.Common;
    using MarketPulse.BusinessLogic.Common.Criteria;
    using MarketPulse.BusinessLogic.Core.System;
    using MarketPulse.BusinessLogic.Legacy;
    using MarketPulse.BusinessLogic.Private;
    using MarketPulse.Reporting.Core;
    using MarketPulse.Reporting.Core.ReportParameters;

#endregion

namespace MarketPulse.Web.Helpers
{
    /// <summary>
    /// Static class used as a session manager to manage the values stored in the session by the application
    /// </summary>
    public static class SessionManager
    {
        #region Enumerations

            /// <summary>
            /// Enumeration used to represent the different actions used when loading the login page
            /// </summary>
            public enum LoginActions
            {
                Login,
                Logout
            }

        #endregion

        #region Properties

            /// <summary>Property used to hold the Language in the Session</summary>
            public static string Language { get { return HttpContext.Current.Session["Language"] as string; } set { HttpContext.Current.Session["Language"] = value; } }                        

            /// <summary> Property to hold the last url visited when doing redirects from login page etc. </summary>
            public static string LastUrl { get { return HttpContext.Current.Session["LastUrl"] as string; } set { HttpContext.Current.Session["LastUrl"] = value; } }

            /// <summary> Property to hold the ApplicationProfile associated with this session.</summary>
            public static ApplicationProfile ApplicationProfile { get { return HttpContext.Current.Session["ApplicationProfile"] as ApplicationProfile; } set { HttpContext.Current.Session["ApplicationProfile"] = value; } }

            /// <summary> Property to hold the TemporaryApplicationProfile associated with this session.</summary>
            public static ApplicationProfile TemporaryProfile { get { return HttpContext.Current.Session["TemporaryProfile"] as ApplicationProfile; } set { HttpContext.Current.Session["TemporaryProfile"] = value; } }

            /// <summary>Checks whether a user is authenticated or not by checking the existence of a current instance of ApplicationProfile.</summary>
            public static bool Authenticated { get { return !(ApplicationProfile == null); } }

            /// <summary>The current ReportingBranch in use for this ApplicationProfile.</summary>
            public static ReportingBranchInfo CurrentBranch { get { return HttpContext.Current.Session["CurrentBranch"] as ReportingBranchInfo; } set { HttpContext.Current.Session["CurrentBranch"] = value; } }

            /// <summary>The current ReportingPeriod in use for this ApplicationProfile.</summary>
            public static ReportingPeriodInfo CurrentPeriod { get { return HttpContext.Current.Session["CurrentPeriod"] as ReportingPeriodInfo; } set { HttpContext.Current.Session["CurrentPeriod"] = value; } }

            /// <summary>A list of available ReportingPeriods for this ApplicationProfile.</summary>
            public static ReportingPeriodInfoList ReportingPeriods { get { return HttpContext.Current.Session["ReportingPeriods"] as ReportingPeriodInfoList; } set { HttpContext.Current.Session["ReportingPeriods"] = value; } }

            /// <summary>A list of available ReportingLevels for this ApplicationProfile.</summary>
            public static ReportingLevelInfoList ReportingLevels { get { return HttpContext.Current.Session["ReportingLevels"] as ReportingLevelInfoList; } set { HttpContext.Current.Session["ReportingLevels"] = value; } }

            /// <summary>A list of reporting visits available</summary>
            public static ReportingBranchInfoList ReportingBranches { get { return HttpContext.Current.Session["ReportingBranches"] as ReportingBranchInfoList; } set { HttpContext.Current.Session["ReportingBranches"] = value; } }

            /// <summary>A list of branches available with data based on period and reporting level</summary>
            public static ReportingVisitInfoList ReportingVisits { get { return HttpContext.Current.Session["ReportingVisits"] as ReportingVisitInfoList; } set { HttpContext.Current.Session["ReportingVisits"] = value; } }

            /// <summary>The current Visit object being interacted with</summary>
            public static Visit Visit { get { return HttpContext.Current.Session["Visit"] as Visit; } set { HttpContext.Current.Session["Visit"] = value; } }

            /// <summary>A map of the responses for a given survey</summary>
            public static Dictionary<Guid, Dictionary<Guid, string>> ResponseMap { get { return HttpContext.Current.Session["ResponseMap"] as Dictionary<Guid, Dictionary<Guid, string>>; } set { HttpContext.Current.Session["ResponseMap"] = value; } }

            /// <summary>A list of available languages</summary>
            public static LanguageInfoList AvailableLanguages { get { return HttpContext.Current.Session["AvailableLanguages"] as LanguageInfoList; } set { HttpContext.Current.Session["AvailableLanguages"] = value; } }

            /// <summary>A list of available Countries</summary>
            public static CountryInfoList AvailableCountries { get { return HttpContext.Current.Session["AvailableCountries"] as CountryInfoList; } set { HttpContext.Current.Session["AvailableCountries"] = value; } }

            /// <summary>A list of available branches</summary>
            public static BranchInfoList AvailableBranches { get { return HttpContext.Current.Session["AvailableBranches"] as BranchInfoList; } set { HttpContext.Current.Session["AvailableBranches"] = value; } }

            /// <summary>A list of available visits</summary>
            public static VisitInfoList AvailableVisits { get { return HttpContext.Current.Session["AvailableVisits"] as VisitInfoList; } set { HttpContext.Current.Session["AvailableVisits"] = value; } }

            /// <summary>A list of available Enquiry Reasons</summary>
            public static EnquiryReasonInfoList AvailableEnquiryReasons { get { return HttpContext.Current.Session["AvailableEnquiryReasons"] as EnquiryReasonInfoList; } set { HttpContext.Current.Session["AvailableEnquiryReasons"] = value; } }

            /// <summary>A list of available Enquiry Types</summary>
            public static EnquiryTypeInfoList AvailableEnquiryTypes { get { return HttpContext.Current.Session["AvailableEnquiryTypes"] as EnquiryTypeInfoList; } set { HttpContext.Current.Session["AvailableEnquiryTypes"] = value; } }

            /// <summary>A list of available Enquiry Action Types</summary>
            public static EnquiryActionTypeInfoList AvailableEnquiryActionTypes { get { return HttpContext.Current.Session["AvailableEnquiryActionTypes"] as EnquiryActionTypeInfoList; } set { HttpContext.Current.Session["AvailableEnquiryActionTypes"] = value; } }

            /// <summary>A list of accreditations available</summary>
            public static AccreditationInfoList AvailableAccreditations { get { return HttpContext.Current.Session["AvailableAccreditations"] as AccreditationInfoList; } set { HttpContext.Current.Session["AvailableAccreditations"] = value; } }

            /// <summary>The current Accreditation object being interacted with</summary>
            public static MarketPulse.BusinessLogic.Legacy.Accreditation Accreditation { get { return HttpContext.Current.Session["Accreditation"] as MarketPulse.BusinessLogic.Legacy.Accreditation; } set { HttpContext.Current.Session["Accreditation"] = value; } }

            /// <summary>The criteria object used as part of the Assignment Search</summary>
            public static AssignmentSearchCriteria AssignmentSearchCriteria { get { return HttpContext.Current.Session["AssignmentSearchCriteria"] as AssignmentSearchCriteria; } set { HttpContext.Current.Session["AssignmentSearchCriteria"] = value; } }

            // TODO Refactor to use parameter collection later
            /// <summary>The Parameter object for the McDonalds Site Report</summary>
            public static VisitReportPage1Parameter VisitReportPage1Parameter { get { return HttpContext.Current.Session["VisitReportPage1Parameter"] as VisitReportPage1Parameter; } set { HttpContext.Current.Session["VisitReportPage1Parameter"] = value; } }

            /// <summary>The ActiveController</summary>
            public static string ActiveController { get { return HttpContext.Current.Session["ActiveController"] as string; } set { HttpContext.Current.Session["ActiveController"] = value; } }

            /// <summary>The ActiveAction</summary>
            public static string ActiveAction { get { return HttpContext.Current.Session["ActiveAction"] as string; } set { HttpContext.Current.Session["ActiveAction"] = value; } }

        #endregion

        #region Static Methods

            /// <summary>Method that resets the session content.</summary>
            public static void Reset()
            {
                HttpContext.Current.Session.Clear();
            }           

        #endregion
    }
}